//初始化树形结构
function initTree(json) {
	eval("var clicks=" + json.clicks);
	$.ajax({
	    url: host + "showAction/getTreeData.html",
	    type: 'POST',
	    async: false,
	    data:{"code": json.code},
	    dataType: 'json',
	    success: function(data) {
			var list = formatTreeData(data.data, data.fields);
			var layout = createLayout(json);
			var tree = $("<ul></ul>");
			layout.append(tree);
			pageParam.trees[json.code] = tree.tree({
				data: list,
				lines: true,
				onClick: function(node){
					if (clicks && clicks.click) {
						clicks.click.handler(node, json.code);
					}
				}
			});
		}
	});
}
function formatTreeData(data, fields) {
	var nodes = [];
	var map = {};
	for (var i = 0;i < data.length;i ++) {
		map[data[i][fields.id]] = {
				id: data[i][fields.id],
				text: data[i][fields.text],
				state: 'open'
			};
		if (map[data[i][fields.parentId]] != undefined) {
			if (map[data[i][fields.parentId]].children == undefined) {
				map[data[i][fields.parentId]].children = [];
			}
			map[data[i][fields.parentId]].children.push(map[data[i][fields.id]]);
		} else {
			nodes.push(map[data[i][fields.id]]);
		}
	}
	return nodes;
}